<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>采购单打印</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <script src="/chineseMoney.js"></script>
    <script src="/tools.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <h3 style="text-align: center">采购单</h3>
    <br/>
    <table width="100%">
        <tr>
            <td width="25%">单号：</td><td width="25%"><span class="billNo"></span></td>
            <td width="25%">采购日期：</td><td width="25%"><span class="purchaseDate"></span></td>
        </tr>
        <tr>
            <td width="25%">采购人：</td><td width="25%"><span class="purchasePerson"></span></td>
            <td width="25%">供应商：</td><td width="25%"><span class="supplier"></span></td>
        </tr>
        <tr>
            <td width="25%">总金额：</td><td width="25%"><span class="amountOfMoney"></span></td>
            <td width="25%">大写：</td><td width="25%"><span class="chineseMoney"></span></td>
        </tr>
    </table>
    <br/>
    <table style="width: 100%;" class="printTable">
        <thead style="border: 1px solid">
            <td width="20%">名称</td>
            <td width="15%">规格</td>
            <td width="15%">品牌</td>
            <td width="10%">单位</td>
            <td width="10%">进货价</td>
            <td width="13%">数量</td>
            <td width="13%">金额</td>
            <td width="4%" id="originalProcess">-</td>
        </thead>
        <tbody class="content">
        </tbody>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var billIds = params.billIds;
    var backAddress = params.backAddress;
    var originalProcess = params.originalProcess;
    for (var i = 1 ; i < billIds.length ; i++) {
            var node = $("#receiptPrintArea0").clone(true);
            node.attr("id","receiptPrintArea" + i);
            $('body').append(node);
    }
    if (originalProcess) $('#originalProcess').show() ;
    else $('#originalProcess').hide() ;
    function print(no) {
        $("#receiptPrintArea" + no).printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
            url: backAddress + "/api/purchase/queryPrintPurchaseBill",
            data : {
                billIds : billIds
            },
            type: "post",
            dataType: "json",
            traditional : true,
            success: function (data) {
                //console.log(data)
                for (var k = 0 ; k < data.data.length ; k++){
                    $(".amountOfMoney")[k].innerText = data.data[k].amountOfMoney;
                    $(".chineseMoney")[k].innerText = Arabia_to_Chinese(data.data[k].amountOfMoney + '');
                    $(".billNo")[k].innerText = data.data[k].id;
                    $(".purchaseDate")[k].innerText = data.data[k].purchaseDate;
                    $(".purchasePerson")[k].innerText = data.data[k].purchasePersonName;
                    $(".supplier")[k].innerText = data.data[k].supplierName ;
                    var str = '' ;
                    for (var i = 0 ; i < data.data[k].details.length ; i++) {
                        str += "<tr><td width=\"20%\">" + data.data[k].details[i].foodMaterialName + "</td>" +
                            "<td width=\"15%\">" + dealNull(data.data[k].details[i].specs) + "</td>" +
                            "<td width=\"15%\">" + dealNull(data.data[k].details[i].brand) + "</td>" +
                            "<td width=\"10%\">" + dealNull(data.data[k].details[i].unitName) + "</td>" +
                            "<td width=\"10%\">" + data.data[k].details[i].price + "</td>" +
                            "<td width=\"13%\">" + data.data[k].details[i].amount + "</td>" +
                            "<td width=\"13%\">" + data.data[k].details[i].total + "</td>" ;
                        if (originalProcess)
                            str += "<td width=\"4%\">" + getOriginalProcessShow(data.data[k].details[i].originalProcess) + "</td>" ;
                        str += '</tr>' ;
                    }
                    $(".content")[k].innerHTML = str;
                    print(k)
                }
            },
            error: function (status) {
                alert(status)
            }
        }
    )
</script>
</body>
</html>